clear all
set more off

cd "/Users/innoshuadmin/Box Sync/DRD/functions"

* The tables and graphs of the paper are produced in R.
* This code matches the results for Table 1 and demonstrates how to use the DRD.ado file in Stata.
* To reproduce the robustness check tables, please refer to the R codes.
 
* There is a very small difference between the results produced using this code and those produced by R.
* This is due to rounding errors. For example, the rdbwselect codes in R and Stata give the same 
* robust bandwidth up to the third decimal place.  

forval sampleid= 1/1 {
use "/Users/innoshuadmin/Box Sync/DRD/APP1/romanian_2sch.dta", clear
if `sampleid'==1 {
keep if dzag!=0 & bcg_Dmean!=.
} 
else if `sampleid'==2 {
keep if dzag!=0 & bcg_Dmean!=. & zga>=7.37
} 
else if `sampleid'==3 {
keep if dzag!=0 & bcg_Dmean!=. & zga<7.37
}

if (`sampleid'==1){
qui rdbwselect bcg_Dmean dzag
scalar hcct=e(h_CCT)
scalar nobs=e(N_l)+e(N_r)
local hrot=hcct*nobs^(1/5-1/4.5)
di `hrot'
}
* Note that to use the DRD command properly both Y and X cannot have missing values.
DRD bcg_Dmean dzag, gen(ksstat_iter) h(`hrot') nygrid(1000) iter(1)
return list
sum ksstat_iter
}
